/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>Project: app2022 - List3
 * <p>Powered by webrx On 2022-01-14 16:19:47
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class List3 {
    public static void main(String[] args) {
        //固定的List
        var list1 = Arrays.asList(10,20,30,40);
        System.out.println(list1.get(0));
        //list1.remove(30);错误

        var list2 = List.of(1,2,3);
        //list2.clear(); 错误
        //list2.add(5);
        System.out.println(list2);


        //动态List
        var list3 = new ArrayList<Integer>();
        var list4 = new ArrayList<String>(List.of("java","php","mysql"));
        var list5 = new ArrayList<Integer>(Arrays.asList(10,20,30));
        list5.add(40);
        list4.add("python");
        list3.addAll(List.of(11,22,33,44));
        System.out.println(list3);
        System.out.println(list4);
        System.out.println(list5);

        //数组转换List
        Integer[] nums = new Integer[]{100,200,300};
        var list6 = new ArrayList<Integer>(Arrays.asList(nums));
        list6.clear();
        System.out.println(list6);

        //List转换为Array数组
        List<String> list7 = new ArrayList<>();
        list7.addAll(List.of("java","springmvc","springboot"));
        System.out.println(list7.size());
        list7.remove("springmvc");
        //Object[] ss = list7.toArray();
        //System.out.println(Arrays.toString(ss));

        String[] ss = new String[list7.size()];
        list7.toArray(ss);
        System.out.println(list7);
        System.out.println(Arrays.toString(ss));


    }
}
